package com.richard.room.operator.api.builder;

import androidx.room.RoomDatabase;

import com.richard.room.operator.api.helper.SQLiteHelper;
import com.richard.room.operator.api.statement.UpdateSQL;

/**
 * @author: Richard
 * @createDate: 2023/8/16 17:12
 * @version: 1.0
 * @description: update builder
 */
public class UpdateBuilder<T> extends BasicConditionRelationBuilder<T, UpdateBuilder<T>> {

    private final RoomDatabase db;
    private final UpdateSQL sql;

    public UpdateBuilder(RoomDatabase db, UpdateSQL updateSQL) {
        this.db = db;
        this.sql = updateSQL;
        this.sql.where = super.condition;
    }

    public void update() {
        SQLiteHelper.execUpdateSql(db, sql,false);
    }

    /**
     * 更新并且返回影响行数
     * @return 影响行数
     */
    public long updateAndReturnRowCount() {
        return SQLiteHelper.execUpdateSql(db, sql,true);
    }
}
